package com.lavegue.dao.impl;

import java.util.List;

import com.lavegue.common.BaseHibernateDao;
import com.lavegue.dao.AreaDao;
import com.lavegue.model.Area;
import com.sun.org.apache.bcel.internal.generic.NEW;

/**
 * author: luoweibin date:2010-10-29 description:
 * 
 */
public class AreaDaoImpl extends BaseHibernateDao<Area, Integer> implements
		AreaDao {

	public AreaDaoImpl() {
		super(Area.class);
	}

	public List<Area> findAreaByParendIdAndlvType(int parendId, int lvType) {
		String sql = "from Area where parentId=" + parendId + " and lvType="
				+ lvType;
		System.out.println("查省份Sql===="+sql);
		return this.getHibernateTemplate().find(sql);
	}

	/**
	 * ljp 20101103
	 * 
	 * @param name
	 *            省，市，区县 根据名称获取数据
	 */
	public List<Area> findAreaByName(String name) {
		String sql = "from Area where name='" + name + "'";
		return this.getHibernateTemplate().find(sql);
	}

	/**
	 * ljp 20101103
	 * 
	 * @param name
	 *            省，市，区县 根据名称获取数据
	 */
	public List<Area> findAreaByName(String name, Integer parentId) {
		String sql = "from Area where name='" + name + "' and parentId="
				+ parentId;
		return this.getHibernateTemplate().find(sql);
	}
	
	/**
	 * ljp 20120306
	 * @param name 省，市，区县 根据名称获取数据
	 */
	public List<Area> findAreaByName(Integer parentId, String name) {
		String sql = "from Area where name like ? and parentId="+ parentId;
		return this.getHibernateTemplate().find(sql,new Object[]{"%" +name + "%"});
	}
	
	/**
	 * ljp 20120306
	 * 
	 * @param name 省，市，区县 根据名称，类型ID获取省的数据       
	 */
	public List<Area> findAreaByNameTypeid(Integer lvTypeId, String name) {
		String sql = "from Area where name like ? and lvType="+ lvTypeId;
		return this.getHibernateTemplate().find(sql, new Object[]{"%" +name + "%"});
	}
	
	/**
	 * ljp 20101110
	 * 
	 * @param name
	 *            省，类型ID 根据获取省的数据
	 */
	public List<Area> findAreaByNameTypeid(String name, Integer typeId) {
		String sql = "from Area where name='" + name + "' and lvType=" + typeId;
		return this.getHibernateTemplate().find(sql);
	}

}
